<?php
/*
*  edited by cbq in 2016.03.16
*  新建MY_Controller类，重写smarty中的assign方法和display方法
*/
if (!defined('BASEPATH')) exit('No direct access allowed.');
class MY_Controller extends CI_Controller {
    protected $_URL;
    protected $cismarty;
    protected $siteslist;
    public function __construct(){
        parent::__construct();

        $this->load->model('sites_m');
        $this->load->model('column_m');
        $this->c_ismarty_init();
        $this->_URL=base_url();
        $this->assign('_URL',$this->_URL);

         //加载公共配置文件
        load_confog(_CONFIG);
        $this->assign('getConfig',getConfig());
        
        //获取默认站点
        $where_sites['ismain']=array('=',1);
        $this->siteslist=$this->sites_m->sel($where_sites);
        if($this->siteslist['status']==0){//站点关闭
            $this->display('home/close.html');exit;
        }
        $this->assign('siteslist',$this->siteslist);
    }
    //导航栏显示
    public function navmenu(){
        //获取栏目信息
        $where_column['sitesid']=array('=',$this->siteslist['id']);
        $columnlist=$this->column_m->selall($where_column);
        //二级处理
        $arr=array();
        if(!empty($columnlist)){
            foreach($columnlist as $k=>$v){
                if($v['parentid']==0 && $v['showintop']==1){
                    $arr[]=$v;
                }
            }
            foreach($arr as $k=>$v){
                $v['child']=array();
                foreach($columnlist as $x=>$y){
                    if($v['colid']==$y['parentid'] && $y['navimenu']==1){
                        $v['child'][]=$y;
                    }
                }
                $arr[$k]=$v;
            }
        }
        $this->assign('columnlist',$arr);
    }
    public function assign($key,$val){
        $this->cismarty->assign($key,$val);
    }
    public function display($html){
        $this->cismarty->display($html);
    }
    public function fetch($html){
        return $this->cismarty->fetch($html);
    }
    public function c_ismarty_init(){
        require_once(BASEPATH.'libraries/smarty/Smarty.class.php' );
        $this->cismarty=new Smarty();
        $this->cismarty->template_dir=VIEWPATH;   //默认模版设置
        $this->cismarty->compile_dir=FCPATH."cache/compile";    //编译缓存文件夹路径
        $this->cismarty->cache_dir=FCPATH."cache/cache";  //缓存文件夹路径
        $this->cismarty->left_delimiter   ='{';    //配置变量左侧识别符
        $this->cismarty->right_delimiter  ='}';     //配置变量右侧识别符
        $this->cismarty->caching        = 0;    //是否开启缓存
        $this->cismarty->cache_lifetime =10;  //缓存时间
        $this->cismarty->compile_check=1;
        $this->cismarty->php_handling = 1;
    }
}
?>
